package com.augmentum.oes.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.augmentum.oes.dao.QuestionBackupDao;
import com.augmentum.oes.dao.QuestionDao;
import com.augmentum.oes.model.Exam;
import com.augmentum.oes.model.Question;
import com.augmentum.oes.model.QuestionBack;
import com.augmentum.oes.service.QuestionBackupService;

@Service
public class QuestionBackupServiceImpl implements QuestionBackupService {

    @Resource
    private QuestionBackupDao questionBackDao;

    @Resource
    private QuestionDao questionDao;

    @Override
    public void savePaper(Exam exam) {
        List<QuestionBack> list = new ArrayList<QuestionBack>();
        List<Question> questions = questionDao.getRandomQuestion(exam.getQuestionQuantity());
        for (Question question : questions) {
            QuestionBack questionBack = new QuestionBack();
            questionBack.setQuestion(question.getQuestion());
            questionBack.setAnswerA(question.getAnswerA());
            questionBack.setAnswerB(question.getAnswerB());
            questionBack.setAnswerC(question.getAnswerC());
            questionBack.setAnswerD(question.getAnswerD());
            questionBack.setAnswer(question.getAnswer());
            questionBack.setExam(exam);
            list.add(questionBack);
        }
        questionBackDao.save(list);
    }
}
